/**
 * 终端颜色编码
 */
const terminalTxtColor = {
    red(txt: string) {
        return '\x1B[1;3;31m' + txt + '\x1B[0m';
    },
    blue(txt: string) {
        return '\x1B[94;1m' + txt + '\x1B[0m';
    },
    green(txt: string) {
        return '\x1B[32;1m' + txt + '\x1B[0m';
    },
};

/**
 * 休眠
 */
function sleep(ms: number): Promise<void> {
    return new Promise(resolve => setTimeout(resolve, ms));
}

/**
 * 返回指定位数的随机编码
 */
function random(digits = 5): string {
    const code = [];
    for (let i = 0; i < digits; i++) {
        code[i] = Math.floor(Math.random() * 10);
    }
    while (code[0] === 0) {
        code[0] += Math.floor(Math.random() * 10);
    }
    return code.join('');
}

// as help
export default {
    sleep,
    random,

    terminalTxtColor,
};
